package com.huawei.appgallery.productpurchase.impl.processor;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.iap.BuyResultInfo;
import com.huawei.hms.support.api.iap.json.Iap;
import com.huawei.secure.android.common.intent.SafeIntent;
import com.huawei.updatesdk.service.otaupdate.UpdateKey;
import o.ayy;
import o.crf;
import o.cro;
import o.evd;

public class IapJumpActivity extends Activity {
    private int ˏ;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        crf.ˎ.ˋ("IapJumpActivity", "IapJumpActivity onCreate");
        ayy.ˋ().ˎ(getWindow());
        if (VERSION.SDK_INT >= 21) {
            evd.ˏ(getWindow());
        }
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        SafeIntent safeIntent = new SafeIntent(getIntent());
        if (getIntent() == null) {
            crf.ˎ.ˏ("IapJumpActivity", "validCheckIntent Failed.");
            cro.ˏ().ˏ(1);
            finish();
            return;
        }
        this.ˏ = safeIntent.getIntExtra("jump_type", 0);
        if (this.ˏ == 2 || this.ˏ == 3) {
            Bundle bundleExtra = safeIntent.getBundleExtra("status_bundle");
            if (bundleExtra != null) {
                Status status = (Status) bundleExtra.getParcelable(UpdateKey.STATUS);
                if (status != null) {
                    try {
                        status.startResolutionForResult(this, 1);
                        return;
                    } catch (Exception e) {
                        crf.ˎ.ˏ("IapJumpActivity", "Exception");
                        cro.ˏ().ˏ(1);
                        finish();
                        return;
                    }
                }
                cro.ˏ().ˏ(1);
                return;
            }
            crf.ˎ.ˏ("IapJumpActivity", "bundle is null");
            cro.ˏ().ˏ(2);
            finish();
            return;
        }
        crf.ˎ.ˏ("IapJumpActivity", "jumpType invalid");
        cro.ˏ().ˏ(1);
        finish();
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        crf.ˎ.ˋ("IapJumpActivity", "Payment resultCode=" + i2);
        if (i2 == -1) {
            BuyResultInfo buyResultInfoFromIntent = Iap.getIapClient((Activity) this).getBuyResultInfoFromIntent(intent);
            if (buyResultInfoFromIntent != null) {
                ˊ(buyResultInfoFromIntent);
            } else {
                cro.ˏ().ˏ(1);
            }
        } else {
            cro.ˏ().ˏ(1);
        }
        finish();
    }

    private void ˊ(BuyResultInfo buyResultInfo) {
        if (buyResultInfo.getReturnCode() == 0) {
            if (this.ˏ == 3) {
                cro.ˏ().ॱ(buyResultInfo.getInAppPurchaseData(), buyResultInfo.getInAppDataSignature());
            } else if (this.ˏ == 2) {
                cro.ˏ().ˋ();
            }
        } else if (buyResultInfo.getReturnCode() == 60000) {
            crf.ˎ.ˋ("IapJumpActivity", "User cancels the payment.");
            cro.ˏ().ˏ(3);
        } else {
            crf.ˎ.ˏ("IapJumpActivity", "Fail to get the order payment information. status=" + buyResultInfo.getReturnCode());
            cro.ˏ().ˏ(1);
        }
    }
}
